#region

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading;
using System.Web.Http;
using System.Web.Mvc;
using log4net;
using xConnected.Common.Education;
using xConnected.Core.Model;
using xConnected.Service;

#endregion

namespace xConnected.Web.Controllers
{
    public class EducationController : ApiController
    {
        private readonly EducationService _educationService;

        public EducationController(EducationService educationService)
        {
            _educationService = educationService;
        }

        public IEnumerable<Education> List()
        {
            ILog log = LogManager.GetLogger(GetType());
            try
            {
                var educations = _educationService.GetAll();
                return educations;
            }
            catch (Exception ex)
            {
                log.Error(ex.Message + Environment.NewLine + "Stack: " + ex.StackTrace, ex);
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }
        }

        //[System.Web.Mvc.HttpPost]
        //public JsonResult Save(Education education)
        //{
        //    ILog log = LogManager.GetLogger(GetType());
        //    try
        //    {
        //        _educationService.SaveOrUpdate(education);
        //        return Json(education.Id, JsonRequestBehavior.AllowGet);
        //    }
        //    catch (Exception ex)
        //    {
        //        log.Error(ex.Message + System.Environment.NewLine + "Stack: " + ex.StackTrace, ex);
        //        return Json(new { Result = "ERROR", ex.Message }, JsonRequestBehavior.AllowGet);
        //    }
        //}

        //[System.Web.Mvc.HttpPost]
        //public JsonResult DeleteEducation(int id)
        //{
        //    ILog log = LogManager.GetLogger(GetType());
        //    try
        //    {
        //        var education = _educationService.GetById(id);
        //        _educationService.Delete(education);
        //        return Json("OK", JsonRequestBehavior.AllowGet);
        //    }
        //    catch (Exception ex)
        //    {
        //        log.Error(ex.Message + System.Environment.NewLine + "Stack: " + ex.StackTrace, ex);
        //        return Json(new { Result = "ERROR", ex.Message }, JsonRequestBehavior.AllowGet);
        //    }
        //}


        //public JsonResult GetEducationsAutocomplete(string searchTerm, int maxRows)
        //{
        //    ILog log = LogManager.GetLogger(GetType());
        //    try
        //    {
        //        var educations = _educationService.GetAll().ToList().Select(e => new
        //        {
        //            Description = EducationRes.ResourceManager.GetString(e.Key,Thread.CurrentThread.CurrentCulture),
        //            e.Id
        //        });
        //        if (searchTerm != "")
        //        {
        //            educations =
        //                educations.Where(l => l.Description.ToLower().Contains(searchTerm.ToLower())).Take(maxRows);
        //        }
        //        return Json(educations, JsonRequestBehavior.AllowGet);
        //    }
        //    catch (Exception ex)
        //    {
        //        log.Error(ex.Message + Environment.NewLine + "Stack: " + ex.StackTrace, ex);
        //        return Json(new { Result = "ERROR", ex.Message }, JsonRequestBehavior.AllowGet);
        //    }
        //}
    }
}